package com.tiger.weixin.api.impl;

import com.tiger.weixin.api.AbstractWxService;
import com.tiger.weixin.api.WeixinApi;
import com.tiger.weixin.config.WxProperties;
import com.tiger.weixin.dto.UserAccessToken;
import com.tiger.weixin.dto.WxMsgTask;
import com.tiger.weixin.token.AccessTokenContext;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Author: spzhang
 * @Date: Created in 16:05 2023/2/20
 * @Description:
 * @Version:
 */
@Service
public class WeixinApiImpl extends AbstractWxService implements WeixinApi {
    public WeixinApiImpl(RestTemplate weixinRestTemplate, AccessTokenContext context, WxProperties wxProperties) {
        super(weixinRestTemplate, context, wxProperties);
    }

    @Override
    public boolean sendMsg(WxMsgTask msg) {
        return sendTemplateMsg(msg);
    }

    @Override
    public String getOpenId(String code) {
        UserAccessToken authorized = authorized(code);
        return authorized == null ? null : authorized.getOpenid();
    }
}
